<?php
  require_once("includes/config.php"); 
  if($_SERVER["REQUEST_METHOD"] == "POST")
  {
    /*if(!empty($_POST['company_id']))
      $client_id = $_POST['company_id'];
    else
      $client_id = $_POST['client_id'];*/
      
    $result = query("UPDATE contracts SET period = ?, rent_type = ?,mildai_from = ? ,miladi_out = ? ,hijri_in = ? ,hijri_out = ? ,discount = ? ,
    chosen_weekly = ? ,chosen_daily = ? ,chosen_monthly = ? ,contract_status = ?,total=?,apartment_id=? where contract_id = ?"
    
    ,$_POST['period'],$_POST['rent_type'],$_POST['from'],$_POST['to'],$_POST['hijri-from'],$_POST['hijri-to'],$_POST['discount'],$_POST['weekly_price'],$_POST['daily_price'],$_POST['monthly_price'],
     $_POST['what-button'],$_POST['final-price'],$_POST['apartment_id'],$_POST['contract_id']);
      
                
      if($_POST['what-button'] == 2)
      {
        $status = 1;
        $_SESSION['success_message'] = "تم تغيير حالة الوحدة إلى مؤجر"; 
      }
      else if($_POST['what-button'] == 1)
      {
        $status = 6;
         $_SESSION['success_message'] = "تم تعديل العقد بنجاح"; 
      }
      else if($_POST['what-button'] == 3)
      {
        $status = 2;
        $_SESSION['success_message'] = "تم تصفية العقد وتغيير حالة الوحدة إلى فارغ";
      }
        
      $result = query("UPDATE apartments SET status=? where id=?",$status,$_POST['apartment_id']);
      redirect("bookings.php");   
      

  }
	?>